﻿<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
	<link href="static/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css"/>
	<link href="static/h-ui.admin/css/style.css" rel="stylesheet" type="text/css"/>
	<link href="lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet" type="text/css"/>
	<title>后台登录</title>
	<style type="text/css">
		.errMsg { color: red; }
	</style>
</head>
<body>
	<div style="margin-top: 10%;">
		<div id="loginform" class="loginBox">
			<form class="form form-horizontal" action="index.html" method="post">
				<div class="row cl">
					<label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60d;</i></label>
					<div class="formControls col-xs-8">
						<input id="uname" type="text" placeholder="输入账户" class="input-text size-L"/>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60e;</i></label>
					<div class="formControls col-xs-8">
						<input id="passwd" type="password" placeholder="密码" class="input-text size-L"/>
						<div class="errMsg" id="errMsg"></div>
					</div>
				</div>
				<div class="row cl">
					<div class="formControls col-xs-8 col-xs-offset-3">
						<!--<input type="submit" class="btn btn-success radius size-L" value="&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;"/>-->
						<input type="button" class="btn btn-success radius size-L" value="&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;" onclick="dologin();"/>
					</div>
				</div>
			</form>
		</div>
	</div>
</body>
</html>


<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="js/view.js"></script>
<script type="text/javascript">
	$(document).on('keydown', function(event) {
		if (event.which == 13 || event.keyCode == 13) { // Enter键被按下
			event.preventDefault(); // 阻止默认行为，例如换行
			console.log('Enter键被按下');
			// 在这里执行你的代码
			dologin();
		}
	});
	//登录
	function dologin(){
		var formData = {
			uname: $('#uname').val(),
			passwd: $('#passwd').val(),
		};
		var errMsg = $('#errMsg');
		if (formData.uname == '') {
			errMsg.html('账号必须的'); return
		}
		if (formData.passwd == '') {
			errMsg.html('密码必须的'); return
		}
		$.ajax({
			type: 'post',
			url: apiDomain + 'dologin',
			data: formData,
			success: function (res) {
				console.log(res);
				if (res.code < 0) {
					errMsg.html(res.msg);
					layerMsgErr(res.msg); return
				}
				var adminInfo = {
					uid: res.data.uid,
					uname: res.data.uname,
					role_id: res.data.role_id,
					role_name: res.data.role_name,
					depart_id: res.data.depart_id,
					depart_name: res.data.depart_name,
					logtime: res.data.logtime,
					is_leader: res.data.is_leader,
				};
				setAdminInfo({val: adminInfo});
				layerMsgOk('登录成功');
				setTimeout(function(){
					window.location.href = 'index.html';
				}, 500);
			},
			error: function (err) {
				console.log(err);
			}
		});
	}
</script>